package com.yz.lzq.liwushuo.ui.setting;

import android.content.Context;

import com.yz.lzq.liwushuo.ui.modules.comminterface.OnGetSharedPerfenceDataListener;

/**
 * Created by Administrator on 2016/12/12.
 * 主要用于获取SharedPerfence的数据
 */

public class SettingActivityPresenter {
    private Context mContext = null;
    private SettingContract.SettingActivityModelInterface modelInterface = null;
    private SettingContract.SettingActivityViewInterface viewInterface = null;

    public SettingActivityPresenter(Context context) {
        mContext = context;
        modelInterface = new SettingActivityModel();
    }

    public SettingActivityPresenter(Context context, SettingContract.SettingActivityViewInterface viewInterface) {
        this.viewInterface = viewInterface;
        mContext = context;
        modelInterface = new SettingActivityModel();
    }

    /**
     * 向外界暴露获取SharedPerfence的接口
     *
     * @param listener
     */
    public void setOnGetUserSharedPerfence(OnGetSharedPerfenceDataListener listener) {
        modelInterface.readUserSharedPerfence(mContext, listener);
    }

    /**
     * 写入SharedPerfence
     */
    public void writeUserSharedPerfence() {
        modelInterface.writeUserSharedPerfence(mContext,
                viewInterface.getGender(), viewInterface.getGeneration());
//        Toast.makeText(mContext, "写入的结果是gender" + viewInterface.getGender() + "generation" + viewInterface.getGeneration(), Toast.LENGTH_SHORT).show();
    }

    /**
     * 用来显示进入设置性别界面的默认值
     */
    public void showDefaultSexData() {
        setOnGetUserSharedPerfence(new OnGetSharedPerfenceDataListener() {
            @Override
            public void onGetGenderAndGenration(int gender, int genration) {
                viewInterface.setSexDefaultData(gender);
            }
        });
    }

    /**
     * 用来显示进入设置身份界面的默认值
     */
    public void showDefaultIdentityData() {
        setOnGetUserSharedPerfence(new OnGetSharedPerfenceDataListener() {
            @Override
            public void onGetGenderAndGenration(int gender, int genration) {
                viewInterface.setIdentityDefaultData(genration);
            }
        });
    }
}
